package com.ck.dao;

import com.ck.model.chuangke.vo.CkCompanySelectListVO;
import com.ck.model.chuangke.vo.CkDeviceCodeListExportVO;
import com.ck.model.common.Company;
import com.ck.model.common.CompanyDevice;
import com.ck.model.common.User;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.*;
import org.apache.logging.log4j.core.tools.picocli.CommandLine;

import java.util.List;

public interface CompanyMapper {
    @Delete({
        "delete from ck_company",
        "where company_id = #{companyId,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long companyId);

    @Insert({
        "insert into ck_company (company_id, company_name, ",
        "company_code, login_user_name, ",
        "login_password, business_license_no, ",
        "company_logo_url, business_license_url, ",
        "legal_person_id_front_url, legal_person_id_back_url, ",
        "contacts, mobile_phone, ",
        "company_file_dir, add_time, ",
        "add_user_name, update_time, ",
        "update_user_name)",
        "values (#{companyId,jdbcType=BIGINT}, #{companyName,jdbcType=VARCHAR}, ",
        "#{companyCode,jdbcType=VARCHAR}, #{loginUserName,jdbcType=VARCHAR}, ",
        "#{loginPassword,jdbcType=VARCHAR}, #{businessLicenseNo,jdbcType=VARCHAR}, ",
        "#{companyLogoUrl,jdbcType=VARCHAR}, #{businessLicenseUrl,jdbcType=VARCHAR}, ",
        "#{legalPersonIdFrontUrl,jdbcType=VARCHAR}, #{legalPersonIdBackUrl,jdbcType=VARCHAR}, ",
        "#{contacts,jdbcType=VARCHAR}, #{mobilePhone,jdbcType=VARCHAR}, ",
        "#{companyFileDir,jdbcType=VARCHAR}, #{addTime,jdbcType=BIGINT}, ",
        "#{addUserName,jdbcType=VARCHAR}, #{updateTime,jdbcType=BIGINT}, ",
        "#{updateUserName,jdbcType=VARCHAR})"
    })
    int insert(Company record);

    int insertSelective(Company record);

    @Select({
        "select",
        "company_id, company_name, company_code, login_user_name, login_password, business_license_no, ",
        "company_logo_url, business_license_url, legal_person_id_front_url, legal_person_id_back_url, ",
        "contacts, mobile_phone, company_file_dir, add_time, add_user_name, update_time, ",
        "update_user_name",
        "from ck_company",
        "where company_id = #{companyId,jdbcType=BIGINT}"
    })
    Company selectByPrimaryKey(Long companyId);

    int updateByPrimaryKeySelective(Company record);

    @Update({
        "update ck_company",
        "set company_name = #{companyName,jdbcType=VARCHAR},",
          "company_code = #{companyCode,jdbcType=VARCHAR},",
          "login_user_name = #{loginUserName,jdbcType=VARCHAR},",
          "login_password = #{loginPassword,jdbcType=VARCHAR},",
          "business_license_no = #{businessLicenseNo,jdbcType=VARCHAR},",
          "company_logo_url = #{companyLogoUrl,jdbcType=VARCHAR},",
          "business_license_url = #{businessLicenseUrl,jdbcType=VARCHAR},",
          "legal_person_id_front_url = #{legalPersonIdFrontUrl,jdbcType=VARCHAR},",
          "legal_person_id_back_url = #{legalPersonIdBackUrl,jdbcType=VARCHAR},",
          "contacts = #{contacts,jdbcType=VARCHAR},",
          "mobile_phone = #{mobilePhone,jdbcType=VARCHAR},",
          "company_file_dir = #{companyFileDir,jdbcType=VARCHAR},",
          "add_time = #{addTime,jdbcType=BIGINT},",
          "add_user_name = #{addUserName,jdbcType=VARCHAR},",
          "update_time = #{updateTime,jdbcType=BIGINT},",
          "update_user_name = #{updateUserName,jdbcType=VARCHAR}",
        "where company_id = #{companyId,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(Company record);

    /**
     * 获取商家总数
     * @return
     */
    Long getCompanyCount();

    /**
     * 创客后台商家列表分页查询
     * @param companyName
     * @param mobilePhone
     * @return
     */
    Page<Company> listPageCk(@Param("companyName") String companyName, @Param("mobilePhone") String mobilePhone);

    /**
     * 通过商家id查询商家详细信息
     * @param companyId
     * @return
     */
    Company getCompanyInfoById(@Param("companyId") String companyId);

    /**
     * 通过商家名称获取商家条数
     * @param companyName 商家名称
     * @return
     */
    Company getCompanyCountByCompanyName(String companyName);

    /**
     * 商家下拉列表
     * @return List<CkCompanySelectListVO>
     */
    List<CkCompanySelectListVO> listSelect();

    /**
     * 通过商家代码查找对应的超级管理员信息
     * @param companyCode 商家代码
     * @return
     */
    User getAdminUserByCompanyCode(@Param("companyCode") String companyCode);

    /**
     * 通过商家代码查询商家信息
     * @param companyCode
     * @return com.ck.model.common.Company
     * @Date 2018/7/25 15:39
     * @Author hanqr
     **/
    Company getCompanyInfoByCompanyCode(@Param("companyCode") String companyCode);

    /**
     * 添加商家和机器码关联信息
     * @param companyDevice 商家机器码关联信息
     */
    void insertCompanyDevice(CompanyDevice companyDevice);

    /**
     * 删除商家关联的所有机器码
     * @param companyCode 商家代码
     */
    void deleteDeviceCodeByCompanyCode(@Param("companyCode") String companyCode);

    /**
     * 查询所有已绑定商家的终端机器码列表
     * hanqr 2018-08-015
     * @return
     */
    List<String> getCompanyDeviceCodeList();

    /**
     * 根据商家代码查询机器码List
     * @param companyCode 商家代码
     * @return
     */
    List<CkDeviceCodeListExportVO> getDeviceCodeListByCompanyCode(@Param("companyCode") String companyCode);
}